import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router, Params } from '@angular/router';
import { Http, Response, RequestOptions, Headers, URLSearchParams } from '@angular/http';

import { HttpRouter } from '../service/httpRouter'
import { HttpService } from '../service/httpService'

@Component({
  selector: 'app-courseslist',
  templateUrl: './courseslist.component.html',
  styleUrls: ['./courseslist.component.less']
})
export class CourseslistComponent implements OnInit {

  public subscribeList:any[];
  public finish : string;
  public total: string;
  private title = "课程列表";
  private defaultHead = '../../assets/dog.png';
  public child:any = {};
  constructor(
    private httpRouter : HttpRouter,
    private httpService : HttpService,
    public activeRoute: ActivatedRoute
  ){}

  ngOnInit(){
    this.child = JSON.parse(sessionStorage.getItem("child"));
    this.activeRoute.params.subscribe(
      params =>this.getList(params["childId"])
    );
  }

  getList(childId:string){
    let data = new URLSearchParams();
    data.append('childId', childId);

    this.httpService.post(this.httpRouter.getCoursesListURl,data).subscribe(data => {
      if(data.code === "10200"){
        console.log(data);
        this.finish = data.data.finish;
        this.total = data.data.total;
        this.subscribeList = data.data.subscriptions;
      }
    });
  };





}
